/**
 * Created by szc on 2017/1/9.
 */
class FreePanle extends egret.DisplayObjectContainer {

    private totalNum: number;
    private countNum: number;

    private totalpanle: any;
    private countpanle: any;
    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
    }
    private onAddToStage(event: egret.Event) {
        //设置免费游戏的画面
        var freePanle = this;
        freePanle.width = this.stage.stageWidth * 0.22;
        freePanle.height = this.stage.stageHeight * 0.06;
        freePanle.x = this.stage.stageWidth * 0.85 - freePanle.width + 20;
        freePanle.y = this.stage.stageHeight * 0.16 - 55;

        //加载免费游戏底板
        var imgCon = [];
        imgCon['url'] = 'null_png';
        imgCon['width'] = freePanle.width;
        imgCon['height'] = freePanle.height;
        freePanle.addChild(new ImageBitmap(imgCon).getImgPoint());
        //设置免费次数
        var imgCon = [];
        imgCon['url'] = 'free_frequency_png';
        imgCon['width'] = freePanle.width;
        imgCon['height'] = freePanle.height;
        imgCon['x'] = freePanle.height * 0.70;
        // imgCon['y'] = freePanle.height * (1-0.45)/2;
        freePanle.addChild(new ImageBitmap(imgCon).getImgPoint());

        this.totalpanle = new NumPanel(12, 20, 'null_');
        this.totalpanle.x = freePanle.width * 0.08;
        this.totalpanle.y = (freePanle.height - this.totalpanle.height) / 5;
        this.addChild(this.totalpanle);
        // this.totalpanle.setNum(12);

        this.countpanle = new NumPanel(30 * 0.65, 40 * 0.65, 'y_');
        this.countpanle.x = freePanle.width * 0.78;
        this.countpanle.y = (freePanle.height - this.countpanle.height) / 5 - 3;
        this.addChild(this.countpanle);
        // this.countpanle.setNum(12);
    }
    public setFreeNum(total: number, count: number) {
        this.totalpanle.setNum(total);
        this.countpanle.setNum(count);
        this.totalNum = total;
        this.countNum = count;

        if (this.countNum > 9) {
            this.countpanle.x = this.width * 0.82 + 10;
        } else {
            this.countpanle.x = this.width * 0.78 + 10;
        }

         if(this.countNum>0){
             this.alpha = 1;
         } else{
            this.alpha = 0;
         }
    }

    public ishasFree(): any {
        if (this.countNum > 0) {
            return true;
        } else {
            return false;
        }
    }
    public userFree(): void {
        this.setFreeNum(this.totalNum, this.countNum - 1);
    }
}